<template>
  <div class="page-login">
    <div class="container">
      <h3 class="title">系统登录</h3>
      <el-form ref="formRef" :rules="rules" :model="formData" size="small">
        <!-- 用户名 -->
        <el-form-item prop="account">
          <el-input
            prefix-icon="iconfont icon-user"
            v-model="formData.account"
          ></el-input>
        </el-form-item>
        <!-- 密码 -->
        <el-form-item prop="password">
          <el-input
            :type="flag ? 'text' : 'password'"
            v-model="formData.password"
            @keyup.native.enter="submit"
          >
            <i slot="prefix" class="iconfont icon-password"></i>
            <i
              @click="flag = !flag"
              slot="suffix"
              class="iconfont"
              :class="flag ? 'icon-eye-open' : 'icon-eye-close'"
            ></i>
          </el-input>
        </el-form-item>
        <!-- 登录 -->
        <el-form-item>
          <el-button @click="submit" type="primary" class="btn">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
//辅助函数，登录用
import { mapActions,mapState } from "vuex";

export default {
  data() {
    return {
      //表单数据
      formData: {
        account: "",
        password: "",
      },
      //眼睛
      flag: false,
      rules: {
        account: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          {
            min: 3,
            max: 12,
            message: "长度在 3 到 12 个字符",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 6,
            max: 12,
            message: "长度在 6 到 12 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  
  computed:{
    //查看token有没有值   
    ...mapState("user",['token',"role"]),
  },
   

  methods: {
    //解构vuex的 user数据，this.$store.state.简写
    ...mapActions("user", ["A_login"]),
    submit() {
      this.$refs.formRef.validate(async (v) => {
        //判断
        if (v) {
          //发送请求
         await this.A_login(this.formData);//
          this.$router.push("/home");
        } else {
          console.log("验证失败");
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.page-login {
  height: 100%;
  // background: $menuBg;
  background: url("@/assets/imgs/daxiong.jpg") top center no-repeat;
  background-size: cover;
}
.container {
  width: 300px;
  height: 300px;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  .title {
    text-align: center;
    color: white;
    font-weight: bold;
    margin-bottom: 20px;
  }
  .btn {
    width: 100%;
  }
}


// ::v-deep .el-input__inner {
//   background-color: transparent;
// }
:deep(.el-input__inner) {
  background-color: transparent;
  color: white;
}
</style>
